package com.example.testdemo.recyclerview_gallery_load;

import android.content.Context;
import android.support.design.widget.CoordinatorLayout;
import android.util.AttributeSet;
import android.view.MotionEvent;

/**
 * Created by MrYan on 2018/8/11.
 */

public class MyCoordinatorLayout extends CoordinatorLayout {

    private int HOVER_TAP_SLOP;
    private int Y;


    public MyCoordinatorLayout(Context context) {
        super(context);
    }

    public MyCoordinatorLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init() {
        HOVER_TAP_SLOP = 20;
    }


    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                Y = (int) ev.getY();
                break;
            case MotionEvent.ACTION_MOVE:
                if (Y - ev.getY() > HOVER_TAP_SLOP){
                    //认为是向上滚动
                    return super.onInterceptTouchEvent(ev);
                }
                if (ev.getY() - Y > HOVER_TAP_SLOP){
                    //认为是向下滚动
                    return false;
                }
                break;
        }
        return super.onInterceptTouchEvent(ev);
    }
}
